# coding: utf-8

import os
import logging
import traceback
from logging.config import dictConfig
from logging.handlers import TimedRotatingFileHandler
from config import base_path


def getMLogger(log_name, format="[%(asctime)s] %(message)s", logpath='./logs/%s.log'):
    logger = logging.getLogger(log_name)
    log_path = os.path.join(base_path, 'logs')
    if not os.path.exists(log_path):
        os.mkdir(log_path)
    if not logger.handlers:
        logger.setLevel(logging.DEBUG)
        handler = TimedRotatingFileHandler(os.path.join(base_path, logpath % log_name), when='D')
        # handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter(format)
        handler.setFormatter(formatter)
        logger.addHandler(handler)
    return logger

logger = getMLogger("main")
user_logger = getMLogger("user_logger")
cronjob_logger = getMLogger("cronjob")